import pandas as pd
import sys

def check_file(file_path):
    """Check the contents of the Excel file"""
    print(f"Checking file: {file_path}")
    
    # Get all sheet names
    excel_file = pd.ExcelFile(file_path)
    sheet_names = excel_file.sheet_names
    print(f"Found sheets: {sheet_names}")
    
    # Check a detail sheet
    detail_sheet = None
    for sheet in sheet_names:
        if "明细" in sheet:
            detail_sheet = sheet
            break
    
    if detail_sheet:
        print(f"\nExamining detail sheet: {detail_sheet}")
        # Read with header at row 1 (0-indexed)
        df_detail = pd.read_excel(file_path, sheet_name=detail_sheet, header=0)
        print("\nDetail sheet headers:")
        for i, col in enumerate(df_detail.columns):
            print(f"{i+1}. {col}")
        
        # Check if we have refunded orders
        has_refunded = False
        if "订单状态" in df_detail.columns:
            refunded_count = (df_detail["订单状态"] == "已退款").sum()
            has_refunded = refunded_count > 0
        
        print(f"\nIncludes refunded orders: {has_refunded}")
        print(f"Number of refunded orders: {refunded_count if has_refunded else 0}")
        
        # Check if we have the required additional columns
        has_order_status = "订单状态" in df_detail.columns
        has_settlement_entity = "结算主体" in df_detail.columns
        
        print(f"Has order status column: {has_order_status}")
        print(f"Has settlement entity column: {has_settlement_entity}")
    
    # Check a summary sheet
    summary_sheet = None
    for sheet in sheet_names:
        if "汇总" in sheet:
            summary_sheet = sheet
            break
    
    if summary_sheet:
        print(f"\nExamining summary sheet: {summary_sheet}")
        # Read with header at row 5 (0-indexed)
        df_summary = pd.read_excel(file_path, sheet_name=summary_sheet, header=4)
        print("\nSummary sheet headers:")
        for i, col in enumerate(df_summary.columns):
            print(f"{i+1}. {col}")

if __name__ == "__main__":
    file_path = "企业结算对账单.xlsx"
    check_file(file_path) 